import { ref } from 'vue';
import { useMessage } from '@/hooks/useMessage';
export const useTag = (formData: any) => {
  const inputValue = ref('');
  const InputRef = ref();
  const { createMessage } = useMessage();
  const handleClose = (tag: string) => {
    console.log('selectag', tag);
    console.log('tag', formData.tag);
    console.log('tag-index', formData.tags.indexOf(tag));
    formData.tags.splice(formData.tags.indexOf(tag), 1);
  };
  const handleInputConfirm = () => {
    if (inputValue.value) {
      if (formData.tags.length === 5) {
        createMessage.warning('标签最多添加5个！');
      } else {
        formData.tags.push(inputValue.value);
      }
    }
    inputValue.value = '';
  };
  return {
    handleInputConfirm,
    handleClose,
    InputRef,
    inputValue
  };
};
